window._MTT = {

    showUi:function(parentNode){

        var talkLabelObj = _GRM.getNodeObj('taskTips');

        if(talkLabelObj.isnew){

            _MTT.initButton(talkLabelObj.node);

        }


        _MTT.refreshUi(talkLabelObj.node);


        parentNode.addChild(talkLabelObj.node);
    },

    initButton:function(talkLabelObj){

        var btns = talkLabelObj.getChildByName('btns').getChildren();
        /*
        var maskNode = talkLabelObj.getChildByName('mask');
        maskNode.on(cc.Node.EventType.TOUCH_START, function(){
            _GRM.putNode(this);
        }, talkLabelObj);
        */

        for(var i=0;i<btns.length;i++){
            btns[i].tipsLabel = talkLabelObj;
            btns[i].getChildByName('goods').on(cc.Node.EventType.TOUCH_START, function(){
                console.log(CSEX[this.optionName].equip);
                _MGD.showGoodsUi(_MAP.node,
                    _IOF.createObjByName(CSEX[this.optionName].equip),
                    {pos:_MGD._POSTUJ});
            },btns[i]);
            btns[i].getChildByName('btn_tonyong').on(cc.Node.EventType.TOUCH_START, function(){
                console.log(this.optionName);
                _GRM.putNode(this.tipsLabel);
                if(_MAINTASK[this.optionName]){
                    _MXYT.pushTask(this.optionName);
                    var msg = "解锁任务【"+this.optionName+"】 解锁地图【"+_MAINTASK[this.optionName].map+"】\n";
                    if(CSEX[this.optionName]){

                        var equipname = CSEX[this.optionName].equip;
                        if(equipname&&_EQUIP[equipname]){
                            _GAMEDATAHELPER.pushItem(_IOF.createObjByName(equipname,{qua:'SS'}));
                            msg+="获得:"+equipname+"\n";
                        }

                        if(CSEX[this.optionName].select=='gongli'){
                            msg += '功利+100';
                        }else if(CSEX[this.optionName].select=='ziyou'){
                            msg += '自由+100';
                        }else if(CSEX[this.optionName].select=='xinyang'){
                            msg += '信仰+100';
                        }


                        _GAMEDATAHELPER.setSelectValue(CSEX[this.optionName].select,100);
                        _MAP.refreshbars();
                    }
                    _TIPS.showMessage(msg);
                }
                _MXYT.refreshUi(_MAP.taskListNode);
            }, btns[i]);

        }

    },

    refreshUi:function(talkLabelObj){

        var messageNode = talkLabelObj.getChildByName('message');
        var btns = talkLabelObj.getChildByName('btns').getChildren();

        var messageObj = _MXYT.getReward(window.gameData.workList[0]);
        var msg = messageObj.msg;
        var option = messageObj.option;

        messageNode.getComponent(cc.Label).string = msg;

        for(var i=0;i<btns.length;i++){
            btns[i].active = false;
        }

        for(var i=0;i<option.length;i++){

            var realoption = option[i];
            _MTT.refreshBtn(btns[i],realoption);
            btns[i].active = true;
            btns[i].getChildByName('btn_tonyong')
                .getChildByName('option1').getComponent(cc.Label).string = realoption;
            btns[i].optionName = option[i];
        }
    },

    refreshBtn:function(btn,realoption){

        var mapnode = btn.getChildByName('map');
        var goodsnode = btn.getChildByName('goods');
        var selectnode = btn.getChildByName('select');
        var iconnode = selectnode.getChildByName('icon');

        if(_MAINTASK[realoption]){
         
            if(_MAINTASK[realoption].map){
                mapnode.active = true;
                mapnode.getChildByName('mapname')
                .getComponent(cc.Label).string = _MAINTASK[realoption].map;
            }
            
            if(CSEX[realoption]){

                goodsnode.active = true;
                goodsnode.getChildByName('img')
                .getComponent(cc.Sprite).spriteFrame =  _GRM.getEquipFrame(CSEX[realoption].equip);;
                goodsnode.getChildByName('nmb')
                .getComponent(cc.Label).string = CSEX[realoption].equip;

                selectnode.active = true;
                if(CSEX[realoption].select=='gongli'){
                    selectnode.getChildByName('nmb')
                    .getComponent(cc.Label).string = '功利+100';

                    iconnode.getChildByName('img_gong').active= false;
                    iconnode.getChildByName('img_e').active= true;
                    iconnode.getChildByName('img_san').active= false;

                    
                }else if(CSEX[realoption].select=='ziyou'){
                    selectnode.getChildByName('nmb')
                    .getComponent(cc.Label).string = '自由+100';

                    iconnode.getChildByName('img_gong').active= true;
                    iconnode.getChildByName('img_e').active= false;
                    iconnode.getChildByName('img_san').active= false;

                }else if(CSEX[realoption].select=='xinyang'){
                    selectnode.getChildByName('nmb')
                    .getComponent(cc.Label).string = '信仰+100';

                    iconnode.getChildByName('img_gong').active= false;
                    iconnode.getChildByName('img_e').active= false;
                    iconnode.getChildByName('img_san').active= true;
                }
            }

        }else{

            mapnode.active = false;
            selectnode.active = false;
            goodsnode.active = false;

        }
    }

}